import 'package:enterprise_v6_app/app/components/custom_modele/dashed_line.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/personnel_management/personnel_management_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 人员管理
class PersonnelManagementPage extends StatelessWidget {
  PersonnelManagementPage({super.key});

  final controller = Get.put(PersonnelManagementController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
              alignment: Alignment.topCenter,
              padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    CustomTitleChartPage(
                      title: '人员信息',
                      child: ListView.separated(
                          shrinkWrap: true,
                          physics: const NeverScrollableScrollPhysics(),
                          itemBuilder: (BuildContext context, int index) {
                            final title = controller.personnelList[index];
                            final int num = controller.peopleMap[title]!;
                            return _getPersonnelContentView(title: title, num: num);
                          },
                          separatorBuilder: (BuildContext context, int index) {
                            return AppGaps.vGap12;
                          },
                          itemCount: controller.peopleMap.length),
                    ).clickOnce(() {
                      Get.toNamed(AppRoutes.peopleInformationList);
                    }),
                    AppGaps.vGap16,
                    CustomTitleChartPage(
                      title: '值班记录',
                      child: Column(
                        children: [
                          _getContentView(
                            icon: AppImages.icon_be_late,
                            title: '计划值班',
                            num: controller.dutyEntity.planUnDuty!,
                            iconColor: const Color(0xff5C6DFF),
                            numColor: const Color(0xff5C6DFF),
                          ),
                          AppGaps.vGap16,
                          _getContentView(
                            icon: AppImages.icon_toolbox,
                            title: '已下班：',
                            num: controller.dutyEntity.unDuty!,
                            numColor: const Color(0xff33A9FF),
                          ),
                          AppGaps.vGap16,
                          _getContentView(
                            icon: AppImages.icon_leave,
                            title: '请假',
                            num: controller.dutyEntity.askForLeave!,
                            numColor: const Color(0xffFC9900),
                          ),
                        ],
                      ),
                    ).clickOnce(() {
                      Get.toNamed(AppRoutes.dutyRecordsList);
                    }),
                  ],
                ),
              ));
        });
  }

  // 获取人员信息样式
  Widget _getPersonnelContentView({required String title, required int num}) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 4.w),
      decoration: BoxDecoration(
        color: const Color(0xffEEF0FF),
        borderRadius: BorderRadius.circular(8.r),
      ),
      child: Row(
        children: [
          Text(
            title,
            style: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff3141CD),
            ),
          ),
          Expanded(
              child: Container(
            padding: EdgeInsets.symmetric(horizontal: 12.w),
            child: DashedLine(
              axis: Axis.horizontal,
              dashedWidth: 2.w,
              dashedHeight: 1.w,
              count: 25,
              color: const Color(0xFFBCC3FF),
            ),
          )),
          Text(
            num.toString(),
            style: TextStyle(
              fontSize: 16.sp,
              height: 1.2,
              fontWeight: FontWeight.w500,
              color: const Color(0xff5C6DFF),
            ),
          ),
        ],
      ),
    );
  }

  // 获取内容显示
  Widget _getContentView({
    required String icon,
    required String title,
    required int num,
    Color? iconColor,
    Color? numColor,
  }) {
    return Row(
      children: [
        SvgPicture.asset(
          icon,
          colorFilter: iconColor == null ? null : ColorFilter.mode(iconColor, BlendMode.srcIn),
        ),
        AppGaps.hGap6,
        Text(
          title,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        AppGaps.hGap30,
        Expanded(
          child: Container(
            alignment: Alignment.center,
            height: 2.w,
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [
                  Color(0xFFffffff),
                  Color(0xFF5C6DFF),
                ],
              ),
            ),
          ),
        ),
        AppGaps.hGap10,
        Text(
          num.toString(),
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w500,
            color: numColor ?? const Color(0xff5C6DFF),
          ),
        ),
      ],
    );
  }
}
